package com.breadenglish.cms.api.app.gateway.manager;


import com.breadenglish.cms.api.app.gateway.model.BeVip;
import com.breadenglish.cms.api.app.gateway.model.BeVipChatLog;
import com.breadenglish.cms.api.app.gateway.model.MessageVoice;
import com.breadenglish.cms.api.app.gateway.util.Util;
import org.jsondoc.core.annotation.*;
import org.jsondoc.core.pojo.ApiStage;
import org.jsondoc.core.pojo.ApiVisibility;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.stream.Collectors;

@Api(name = "BE VIP", description = "BeVip 资源服务", group = "客户端接口", visibility = ApiVisibility.PUBLIC, stage = ApiStage.RC)
@ApiVersion(since = "1.0", until = "2.12")
@ApiAuthNone
@RestController
@RequestMapping(value = "/{userId}/bevip")
public class BeVipController {

    public static final String file_url = "http://video.breadenglish.com/who_be_like/";
    public static LinkedHashMap<Integer, BeVip> data = new LinkedHashMap();
    LinkedHashMap<Integer, BeVip> dataDetails = new LinkedHashMap();

    public BeVipController() {
        int id = 100;
        LinkedList<BeVipChatLog> chatLogs = new LinkedList<>();
        int clId = 1;
        for (int i = 0; i < 6; i++) {
            chatLogs.add(new BeVipChatLog(clId++, "voice", null, new MessageVoice(10, clId, "10.mp3"), "teacher", Util.parseToDate("2015-07-17")));
            chatLogs.add(new BeVipChatLog(clId++, "voice", null, new MessageVoice(12, clId, "12.mp3"), "teacher", Util.parseToDate("2015-07-17")));
            chatLogs.add(new BeVipChatLog(clId++, "voice", null, new MessageVoice(13, clId, "13.mp3"), "me", Util.parseToDate("2015-07-17")));
            chatLogs.add(new BeVipChatLog(clId++, "voice", null, new MessageVoice(14, clId, "14.mp3"), "teacher", Util.parseToDate("2015-07-17")));
            chatLogs.add(new BeVipChatLog(clId++, "voice", null, new MessageVoice(16, clId, "16.mp3"), "teacher", Util.parseToDate("2015-07-17")));
            chatLogs.add(new BeVipChatLog(clId++, "voice", null, new MessageVoice(19, clId, "19.mp3"), "teacher", Util.parseToDate("2015-07-17")));
            chatLogs.add(new BeVipChatLog(clId++, "voice", null, new MessageVoice(20, clId, "20.mp3"), "me", Util.parseToDate("2015-07-17")));
            chatLogs.add(new BeVipChatLog(clId++, "voice", null, new MessageVoice(21, clId, "21.mp3"), "teacher", Util.parseToDate("2015-07-17")));
            chatLogs.add(new BeVipChatLog(clId++, "voice", null, new MessageVoice(22, clId, "22.mp3"), "me", Util.parseToDate("2015-07-17")));
            chatLogs.add(new BeVipChatLog(clId++, "voice", null, new MessageVoice(23, clId, "23.mp3"), "teacher", Util.parseToDate("2015-07-17")));
            chatLogs.add(new BeVipChatLog(clId++, "voice", null, new MessageVoice(24, clId, "24.mp3"), "teacher", Util.parseToDate("2015-07-17")));


        }

        dataDetails.put(id, BeVip.buildDetails(id, "Vivi Barbara1", "出国旅游", "21:00-21:30", Util.parseToDate("2016-01-06"), "http://audio.breadenglish.com/0042af909fbff4bb0b1875e4b2ad121c/2015-12-14.zip", chatLogs, "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 1));
        data.put(id, BeVip.build(id--, "Vivi Barbara2", "留学计划", "21:00-21:30", Util.parseToDate("2016-01-06"), "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 1));
        dataDetails.put(id, BeVip.buildDetails(id, "Vivi Barbara1", "出国旅游", "10:00-11:30", Util.parseToDate("2016-01-07"), "http://audio.breadenglish.com/0042af909fbff4bb0b1875e4b2ad121c/2015-12-14.zip", chatLogs, "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 2));
        data.put(id, BeVip.build(id--, "Vivi Barbara3", "商务英语", "10:00-11:30", Util.parseToDate("2016-01-07"), "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 2));
        dataDetails.put(id, BeVip.buildDetails(id, "Vivi Barbara1", "出国旅游", "21:00-21:30", Util.parseToDate("2016-01-08"), "http://audio.breadenglish.com/0042af909fbff4bb0b1875e4b2ad121c/2015-12-14.zip", chatLogs, "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 3));
        data.put(id, BeVip.build(id--, "Vivi Barbara4", "学习", "15:00-15:30", Util.parseToDate("2016-01-08"), "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 3));
        dataDetails.put(id, BeVip.buildDetails(id, "Vivi Barbara1", "出国旅游", "21:00-21:30", Util.parseToDate("2015-07-14"), "http://audio.breadenglish.com/0042af909fbff4bb0b1875e4b2ad121c/2015-12-14.zip", chatLogs, "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 4));
        data.put(id, BeVip.build(id--, "Vivi Barbara5", "儿童英语", "19:00-19:30", Util.parseToDate("2016-01-14"), "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 4));

        dataDetails.put(id, BeVip.buildDetails(id, "Vivi Barbara1", "出国旅游", "21:00-21:30", Util.parseToDate("2016-02-06"), "http://audio.breadenglish.com/0042af909fbff4bb0b1875e4b2ad121c/2015-12-14.zip", chatLogs, "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 1));
        data.put(id, BeVip.build(id--, "Vivi Barbara2", "留学计划", "21:00-21:30", Util.parseToDate("2016-02-06"), "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 1));
        dataDetails.put(id, BeVip.buildDetails(id, "Vivi Barbara1", "出国旅游", "10:00-11:30", Util.parseToDate("2016-02-07"), "http://audio.breadenglish.com/0042af909fbff4bb0b1875e4b2ad121c/2015-12-14.zip", chatLogs, "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 2));
        data.put(id, BeVip.build(id--, "Vivi Barbara3", "商务英语", "10:00-11:30", Util.parseToDate("2016-02-07"), "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 2));
        dataDetails.put(id, BeVip.buildDetails(id, "Vivi Barbara1", "出国旅游", "21:00-21:30", Util.parseToDate("2016-01-08"), "http://audio.breadenglish.com/0042af909fbff4bb0b1875e4b2ad121c/2015-12-14.zip", chatLogs, "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 3));
        data.put(id, BeVip.build(id--, "Vivi Barbara4", "学习", "15:00-15:30", Util.parseToDate("2016-02-08"), "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 3));
        dataDetails.put(id, BeVip.buildDetails(id, "Vivi Barbara1", "出国旅游", "21:00-21:30", Util.parseToDate("2015-02-14"), "http://audio.breadenglish.com/0042af909fbff4bb0b1875e4b2ad121c/2015-12-14.zip", chatLogs, "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 4));
        data.put(id, BeVip.build(id--, "Vivi Barbara5", "儿童英语", "19:00-19:30", Util.parseToDate("2016-02-14"), "Vivi", "http://m.breadenglish.com/Content/RwdImages/M/logo.png", true, 4));

    }

    @ApiMethod
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public
    @ApiResponseObject
    BeVip getById(@ApiPathParam(description = "根据userId获取学员已开课或补课课程数据") @PathVariable(value = "userId") int userId,
                  @ApiPathParam(description = "根据ID获取BE VIP数据") @PathVariable(value = "id") int id) {
        return dataDetails.get(id);
    }

    @ApiMethod
    @RequestMapping(method = RequestMethod.GET)
    public
    @ApiResponseObject
    Collection<BeVip> get(@ApiPathParam(description = "根据userId获取学员已开课或补课课程数据") @PathVariable(value = "userId") int userId,
                          @ApiQueryParam(name = "page", required = false, description = "页号")
                          @RequestParam(required = false, defaultValue = "1") int page,
                          @ApiQueryParam(name = "pageSize", required = false, description = "每页Size")
                          @RequestParam(required = false, defaultValue = "10") int pageSize) {


        int size = 10;
        int p = page - 1;
        return data.values().stream()
                .skip(p * size)
                .limit(size)
                .collect(Collectors.toList());
    }

    @ApiMethod
    @RequestMapping(value = "/schedule", method = RequestMethod.GET)
    public
    @ApiResponseObject
    Collection<BeVip> getSchedule(@ApiPathParam(description = "根据userId获取学员全部课程数据") @PathVariable(value = "userId") int userId,
                                  @ApiQueryParam(name = "page", required = false, description = "页号") @RequestParam(required = false, defaultValue = "1") int page,
                                  @ApiQueryParam(name = "pageSize", required = false, description = "每页Size") @RequestParam(required = false, defaultValue = "10") int pageSize) {


        int size = pageSize;
        int p = page - 1;
        return data.values().stream()
                .skip(p * size)
                .limit(size)
                .collect(Collectors.toList());
    }
}